package com.hist.dao;

import com.hist.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.List;

/**
 * @auther Ren Gaoshuai
 * @date 2021-04-07 19:48
 * 
 * 使用继承类获取session对象
 **/
public class UserMapperImpl2 extends SqlSessionDaoSupport implements UserMapper {
    public List<User> queryUser() {
        SqlSession sqlSession = getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);


        //模拟事务
        mapper.insertUser(new User(8,"gege11","66666"));
        mapper.deleteUser(8);
        mapper.insertUser(new User(9,"gege11","66666"));

        return mapper.queryUser();
    }

    public void deleteUser(Integer id) {
        getSqlSession().getMapper(UserMapper.class).deleteUser(id);
    }

    public void insertUser(User user) {
        getSqlSession().getMapper(UserMapper.class).insertUser(user);
    }
}
